/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package plash.display;

import plash.geom.Point;

/**
 *
 * @author  #0K Srinivasan <hashok.com>
 */
public class GraphicArc extends GraphicLinearPathShape
{
    private int _x;
    private int _y;
    private int _radius;
    private float _startAngle;
    private float _endAngle;
    
    public GraphicArc(Graphics g, int x, int y, int radius, int startAngle, int endAngle)
    {
        super(g);
        Point p1;
        Point p2;
        Point p3;
        
        _x = x;
        _y = y;
        _radius = radius;        
        _startAngle = plash.utils.Math.toRadians(startAngle);
        _endAngle = plash.utils.Math.toRadians(endAngle);
        
        p1 = new Point(x, y);
        p2 = new Point((int)(Math.cos(_startAngle)* radius),(int) (Math.sin(_startAngle)* radius));
        p3 = new Point((int)(Math.cos(_endAngle)* radius), (int)(Math.sin(_endAngle)* radius));
        
        __minPoint.setX(Math.min(p1.getX(), p2.getX()));
        __minPoint.setX(Math.min(__minPoint.getX(), p3.getX()));
        
        __minPoint.setY(Math.min(p1.getY(), p2.getY()));
        __minPoint.setY(Math.min(__minPoint.getY(), p3.getY()));
                
        
        __maxPoint.setX(Math.max(p1.getX(), p2.getX()));
        __maxPoint.setX(Math.max(__maxPoint.getX(), p3.getX()));
        
        __maxPoint.setY(Math.max(p1.getY(), p2.getY()));
        __maxPoint.setY(Math.max(__maxPoint.getY(), p3.getY()));
        
        __boundingBox.setX(__minPoint.getX());
        __boundingBox.setY(__minPoint.getY());
        
        __boundingBox.setWidth(__maxPoint.getX() - __minPoint.getY());
        __boundingBox.setHeight(__maxPoint.getY() - __minPoint.getY());
    }
    

    @Override
    public void execute()
    {
        if(__g == null)
        {
            return;
        }
        if(__g.getOwner().getPainter() == null)
        {
            return;
        }       
        __g.getOwner().getPainter().arc(_x, _y, _radius, _radius, _startAngle, _endAngle);
    }
    
}
